package com.hqyj.crmdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hqyj.crmdemo.entity.Custmer;
import com.hqyj.crmdemo.entity.CustmerName;
import com.hqyj.crmdemo.entity.CustomerLoss;
import com.hqyj.crmdemo.mapper.CustomerLossMapper;
import com.hqyj.crmdemo.mapper.OrdersMapper;
import com.hqyj.crmdemo.service.ICustomerLossService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 何万林
 * @since 2022-10-17
 */
@Service
public class CustomerLossServiceImpl extends ServiceImpl<CustomerLossMapper, CustomerLoss> implements ICustomerLossService {

    @Autowired
    CustomerLossMapper mapper;
    @Autowired
    OrdersMapper ordersMapper;
    @Override
    public CustomerLoss queryOne(Integer lossId) {
        CustomerLoss customerLoss = mapper.selectById(lossId);
        return customerLoss;
    }

    @Override
    public List<CustomerLoss> queryAll() {
        List<CustomerLoss> customerLosses = mapper.selectList(null);
        return customerLosses;
    }

    @Override
    public List<CustomerLoss> queryOne(QueryWrapper queryWrapper) {
        List<CustomerLoss> customerLosses = mapper.selectList(queryWrapper);
        return customerLosses;
    }

    @Override
    public Boolean add(CustomerLoss customerLoss) {
        int insert = mapper.insert(customerLoss);
        return insert > 0 ? true : false;
    }

    @Override
    public Boolean update(CustomerLoss customerLoss) {
        int update = mapper.updateById(customerLoss);
        return update > 0 ? true : false;
    }

    @Override
    public Boolean delete(Integer lossId) {
        int delete = mapper.deleteById(lossId);
        return delete > 0 ? true : false;
    }

    @Override
    @Scheduled(cron = "* * * * 6 ? ")
    public List<CustmerName> selectName() {
        List<CustmerName> custmerNames = ordersMapper.selectName();

        for (CustmerName custmerName : custmerNames) {
            CustomerLoss customerLoss = new CustomerLoss();
            customerLoss.setLossName(custmerName.getCustmerName());
            customerLoss.setLossManager(custmerName.getCustmerManager());
            customerLoss.setLossState("预警");
            int insert = mapper.insert(customerLoss);
        }
        return null;
    }





}
